package com.example.thegreatwall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.thegreatwall.common.R;
import com.example.thegreatwall.entity.ArticleTable;
import com.example.thegreatwall.service.ArticleTableService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin(origins = "*") //无论什么源都可以访问  不写这个不允许跨域
@RestController
@RequestMapping("/articleTable")
public class ArticleTableController{
    /**
     * 查询所有文章
     */
    @Autowired
    private ArticleTableService articleTableService;
    @GetMapping(value = "articleTableList")
    public R articleTableList(@RequestParam int type,@RequestParam int user_id){
        List<ArticleTable> articleTables = this.articleTableService.articleTableList(type, user_id);
        return new R().addDate("articleall",articleTables);
    }

    /**
     *
     * @param articleid
     * @return 对象
     */
    @GetMapping(value = "articleid")
    public R articleid(@RequestParam int articleid){
        return new R().addDate("articleid",articleTableService.getOne(new QueryWrapper<ArticleTable>().eq("article_table_id", articleid)));
    }

}